<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
<style>
	.searchDiv{
		float:left;margin-left:20px;margin-top:10px;display:inline;
	}
</style>
</head>
<body style="font-family: '微软雅黑'" class="easyui-layout">
			<div  id="searchBox" data-options="region:'north',title:'筛选',split:true" style="height:135px;width:100%;">
			 	<#-- 查询框BEGIN -->
				<#if genTable.isSearch??&& genTable.isSearch==1>
				<div style="width:100%;">
				<#list cols as col> 
					<#if col.searchType?? &&col.searchType?trim!="">
				    <#if col.searchType==1 ||col.searchType==3||col.searchType==4>
				    <div class="searchDiv">
				    	<span>${col.colComment}:&nbsp;&nbsp;</span><input 
				    	<#if col.inputType??>
						<#if col.inputType==1>
						type="text" class="easyui-textbox"
						<#elseif col.inputType==2>
						type="text" 
						<#elseif col.inputType==3>
						type="text" class="easyui-datetimebox" 
						<#else>
						 class="easyui-textbox" data-options="multiline:true" style="height:60px"
						</#if>
						<#else>
						type="text" class="easyui-datebox" 
						</#if>
						<#if col.searchType==1>
				    	 name="${col.colName}_EQUAL_LEEKO" style="float:right;"/>
				    	 <#elseif col.searchType==3>
				    	 name="${col.colName}_LIKERIGHT_LEEKO" style="float:right;"/>
				    	 <#else>
				    	 name="${col.colName}_LIKEALL_LEEKO" style="float:right;"/>
				    	</#if>
				    </div>
				    <#else>
				    	<div class="searchDiv">
				    	<span>${col.colComment}:&nbsp;&nbsp;</span> 起:<input 
				    	<#if col.inputType??>
						<#if col.inputType==1>
						type="text"
						<#elseif col.inputType==2>
						type="text" class="easyui-datebox" 
						<#elseif col.inputType==3>
						type="text" class="easyui-datetimebox" 
						<#else>
						 type="text" class="easyui-datebox" 
						</#if>
						<#else>
						type="text" class="easyui-datebox" 
						</#if>
				    	 name="${col.colName}_BEGIN_LEEKO" style="float:right;"/>
				    	 
				    </div>
				    <div class="searchDiv">
				    	<span>${col.colComment}:&nbsp;&nbsp;</span> 止:<input 
				    	<#if col.inputType??>
						<#if col.inputType==1>
						type="text"
						<#elseif col.inputType==2>
						type="text" class="easyui-datebox" 
						<#elseif col.inputType==3>
						type="text" class="easyui-datetimebox" 
						<#else> 
						 type="text" class="easyui-textbox"
						</#if>
						<#else>
						type="text" class="easyui-textbox"
						</#if>
						
				    	 name="${col.colName}_END_LEEKO" style="float:right;"/>
				    	 
				    </div>
				    </#if>
				    </#if>
				</#list>
				<shiro:hasPermission name="${genTable.id}:search">
					<div style="width:100%;height:30px;float:left;margin-top:10px;">
							<a id="btnSearch" style="float:right;margin-right:20px;" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
					</div>
				</shiro:hasPermission>
				</div>
				</#if>
			</div>
			
			<div data-options="region:'center',title:''" style="background:#eee;height:80%" >
				<div id="tb" style="padding: 5px; height: auto">
				<div>
					<shiro:hasPermission name="${genTable.id}:add">
						<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-add"
						onclick="add();">添加</a>
						<span class="toolbar-item dialog-tool-separator"></span> 
					</shiro:hasPermission> 
					
					<shiro:hasPermission name="${genTable.id}:del">
						<a href="#"
						class="easyui-linkbutton" plain="true" iconCls="icon-remove"
						onclick="del()">删除</a>
						<span class="toolbar-item dialog-tool-separator"></span>
					</shiro:hasPermission> 
					
					<shiro:hasPermission name="${genTable.id}:edit">
					    <a href="#"
						class="easyui-linkbutton" plain="true" iconCls="icon-edit"
						onclick="upd()">编辑</a>
						<span class="toolbar-item dialog-tool-separator"></span>
					</shiro:hasPermission>
					
					<shiro:hasPermission name="${genTable.id}:imp">
						<#if genTable.isUpload??&& genTable.isUpload==1>
							<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-undo"
							onclick="upload();">导入</a> <span
							class="toolbar-item dialog-tool-separator"></span> 
						</#if>
					</shiro:hasPermission>
					
					
						<#if genTable.isDownload??&& genTable.isDownload==1>
							<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-redo"
							onclick="javascript:$('#expxz').dialog('open');">导出</a> <span
							class="toolbar-item dialog-tool-separator"></span> 
						</#if>
				</div>
			</div>
			<table id="dg"></table>
		
			<div id="dlg"></div>
			<div id="icon_dlg"></div>
			</div>
			
			<!-- 导出  -->
		    <div class="easyui-dialog" closed="true" id="down">
				<table width="100%" height="100%">
					<tr>
						<td style="text-align:center"><a href="#" style="color:red;" id="downHref">点击下载</a></td>
					</tr>
				</table>
			</div> 
			
			<!-- 导出选择 -->
			 <div class="easyui-dialog" closed="true" id="expxz">
					<table width="100%" height="100%" >
						<tr>
							<td style="text-align:right">按模板导出：</td>
							<td>
								<form id="expModelForm" method="post" enctype="multipart/form-data">
									<input type="file" name="expfile" id="expfile"/></td>
								</form>
							<td><a id="btn" href="javascrap:void(0)" onclick="dowModel()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">导出</a></td>
						</tr>
						<tr>
							<td colspan="3"></br></td>
						</tr>
						<tr>
							<td style="text-align:right">无样式导出：</td>
							<td colspan="2"><a href="javascript:void(0)" onclick="dow()">点击导出</a></td>
						</tr>
					</table>
			</div> 
			
	<script type="text/javascript">
var dg;
var d;
$(function(){   
	dg=$('#dg').datagrid({    
	method: "get",
    url:'<%=path%>/generator/auto/datagrid?id=${genTable.id}', 
    fit : true,
	fitColumns : true,
	border : false,
	striped:true,
	<#if (genTable.isPage)??&&genTable.isPage==1>
		pagination:true,
		rownumbers:true,
		pageNumber:1,
		pageSize : 20,
		pageList : [ 10, 20, 30, 40, 50 ],
	</#if>
	<#if (genTable.showCheckbox)??&&genTable.showCheckbox==1>
	<#else>
	singleSelect:true,
	</#if>
	columns:[[
			<#if (genTable.showCheckbox)??&&genTable.showCheckbox==1>
				{field:'ck',checkbox:true},
			</#if>
			<#list cols as col> 
				<#if  (col.listShow)??&&col.listShow == 1>
				    {field:'${col.colName}',title:'${col.colComment}',width:100
				    <#if  (col.colFormat)??&&col.colFormat?trim!= "">
				     ,formatter:${col.colFormat}
				    </#if>
				    }
	   				<#if col_has_next>,</#if>
				</#if>
			</#list>
		]],
	<#if (genTable.rowFormmat)??&&genTable.rowFormmat?trim!="" >
		,rowStyler:function(index,row){
			${genTable.rowFormmat}
		}
	</#if>
    headerContextMenu: [
        {
            text: "冻结该列", disabled: function (e, field) { return dg.datagrid("getColumnFields", true).contains(field); },
            handler: function (e, field) { dg.datagrid("freezeColumn", field); }
        },
        {
            text: "取消冻结该列", disabled: function (e, field) { return dg.datagrid("getColumnFields", false).contains(field); },
            handler: function (e, field) { dg.datagrid("unfreezeColumn", field); }
        }
    ],
    enableHeaderClickMenu: true,
    enableHeaderContextMenu: true,
    enableRowContextMenu: false,
    toolbar:'#tb'
	});
	$("#btnSearch").click(function(){
		search();
	})
});




var msg="${r'${result}'}";
if(typeof(msg)!='undefined'&&msg!='') {
	layer.msg(msg);
}
	
$('#down').dialog({
	title: '导出',    
    width: 200,    
    height: 100,    
    closed: true,    
    cache: true,
    modal : true
  });
  
  $('#expxz').dialog({
	title: '导出选项',    
    width: 400,    
    height: 130,    
    closed: true,    
    cache: true,
    modal : true
  });

//导出
function dow(){
	$.messager.progress({title:'导出',msg:'导出数据',text:'正在导出'});
	$.ajax({
		url:'<%=path%>/generator/auto/export?tid=${genTable.id}',
		type:'post',
		dataType:'json',
		success:function(data){
			$('#downHref').attr({href:data.obj});
			setTimeout(function () { 
				$.messager.progress('close');
				$('#down').window('open');
				$('#expxz').window('close');
			 }, 4000);  
		}
	});	
}

//根据导入模板导出
function dowModel(){
	$('#expModelForm').form('submit', {    
	    url:'<%=path%>/generator/auto/exportModel',    
	    onSubmit: function(){    
	        
	    },    
	    success:function(data){    
	        alert(data);   
	    }    
	});  
}

var width=parseInt('${genTable.winWidth}');
var height=parseInt('${genTable.winHeight}');
//弹窗增加
function add() {
	d=$("#dlg").dialog({   
	    title: '新增${genTable.gtableComment}',    
	    width:width,    
	    height:height,
	     href:'<%=path%>/generator/auto/toAdd?tid=${genTable.id}&method=add',
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#mainform").submit();
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
		});
}

//删除
function del(){
	var rows = dg.datagrid('getSelections');
	if(rows.length==0) return;
	var ids="";
	for(var i=0;i<rows.length;i++){
		ids=ids+rows[i].ID+",";
	}
	if(ids.length>0){
	ids=ids.substring(0,ids.length-1);
	}
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"<%=path%>/generator/auto/del?tid=${genTable.id}&id="+ids,
				success: function(data){
					if(successTip(data,dg)){
			    		dg.treegrid('reload');
			    	}
				}
			});
		} 
	});

}

//修改
function upd(){
	var rows = dg.datagrid('getSelections');
	var rowid;
	if(rows.length==0) return;
	if(rows.length>1){
		successTip("只能选择一行");
		return;
	}else{
	 rowid=rows[0].ID;	
	}
	d=$("#dlg").dialog({   
	    title: '编辑${genTable.gtableComment}',    
	 	width: ${genTable.winWidth!"1000"},    
	    height: ${genTable.winHeight!"500"}, href:'<%=path%>/generator/auto/toAdd?tid=${genTable.id}&method=edit&id=' +rowid,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#mainform").submit();
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});

		}
//查询	
function search(){
	dg.datagrid('load',{
		searchVal: searchVals()
	});
}

function searchVals() {
	var trArr = []; //存数据
	$("input", $("#searchBox")).each(function() { //便利行内的input select的值
		if(typeof($(this).attr("name"))!="undefined"){ 
			trArr.push("'" + $(this).attr("name")+ "':'" + $(this).val() + "'");
		}
	});
	var value = trArr.join(",");
	value="{"+value+"}";
	//console.log("查询条件："+value);
	return value;
}
	</script>
</body>
</html>